﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace POVRay {
    public class Transformation : Block {
        public LinkedList<TransformationOperation> Operations { get; protected set; }

        public Transformation() {
            Operations = new LinkedList<TransformationOperation>();
        }

        public Transformation(TransformationOperation[] operations) {
            Operations = new LinkedList<TransformationOperation>();
            foreach(TransformationOperation operation in operations) {
                Operations.AddLast(operation);
            }
        }

        public static implicit operator Transformation(Translation translation) {
            Transformation t = new Transformation();
            t.Add(translation);
            return t;
        }

        public static implicit operator Transformation(Rotation rotation) {
            Transformation t = new Transformation();
            t.Add(rotation);
            return t;
        }

        public static implicit operator Transformation(Scale scale) {
            Transformation t = new Transformation();
            t.Add(scale);
            return t;
        }

        public static implicit operator Transformation(TransformationOperation[] operations) {
            return new Transformation(operations);
        }

        public void Add(TransformationOperation operation) {
            Operations.AddLast(operation);
        }

        public void AddTranslation(Vector3 translation) {
            Operations.AddLast(new Translation(translation));
        }

        public void AddRotation(Vector3 rotation) {
            Operations.AddLast(new Rotation(rotation));
        }

        public void AddScale(Vector3 scale) {
            Operations.AddLast(new Scale(scale));
        }

        public void AddScale(float scale) {
            Operations.AddLast(new Scale(scale));
        }

        override public string ToString(int level) {
            StringBuilder representation = new StringBuilder();

            foreach (TransformationOperation operation in Operations) {
                representation.Append(operation.ToString());
                representation.Append(" ");
            }

            return representation.ToString();
        }
    }
}
